import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

import VisualDev from 'visual-dev/plugins/vite';
// 这个path会报错 因为path只在node中运行 ts 没有需要安装 @types/node
import legacy from '@vitejs/plugin-legacy';

import { resolve } from 'path';

const newLocal =
  'https://service-jc86d11n-1306450364.sh.apigw.tencentcs.com/release';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    VisualDev({}),
    legacy({
      targets: ['ie >= 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      polyfills: ['es.array.iterator'],
    }),
  ],
  resolve: {
    alias: [{ find: '@', replacement: resolve(__dirname, 'src') }],
  },
  server: {
    // Listening on all local IPs
    host: true,
    // Load proxy configuration from .env
    proxy: {
      '/dev': {
        target: newLocal,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/dev/, '/dev'),
      },
    },
  },
});
